<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags" %>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix='fmt' uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
   	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <link href="<%=request.getContextPath()%>/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="<%=request.getContextPath()%>/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="<%=request.getContextPath()%>/js/bootstrap.js" type="text/javascript"></script>  
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrapValidator.css"/>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrapValidator.js"></script>
    <script src="<%=request.getContextPath()%>/js/jquery.twbsPagination.js" type="text/javascript"></script>   
    <script type="text/javascript">

    $(document).ready(function () {
	    $('#pagination-demo').twbsPagination({	    	
	        totalPages: ${pageCount},
	        visiblePages: ${pageCount}>10?10:${pageCount},
			startPage:${page},
	        version: '1.1',
	        first: "首页",
	        last: "未页",
	        prev: '上一页',
	        next: '下一页',
	        onPageClick: function (event, page) {	        	
	        	if(page!=${page}){
	        		var params="${params}";
	        		if(params=='showname'){
		        		document.getElementById("queryForm").action="local_product_listByPage.action?params=showname&page="+ page +"&rows=10";
		        		document.getElementById("queryForm").submit();
	        		}
	        		
	        		if(params=='showall'){
	        			//location.href="role/Role_listByPage.action?params=showall&page="+ page +"&rows=10";
	        			document.getElementById("defaultForm").action="<%=request.getContextPath()%>/role/Role_listByPage.action?params=showall&page="+ page +"&rows=10";
		        		document.getElementById("defaultForm").submit();
	        		}
					
	        	}	        	
	        }
	    });
    });
    //弹出修改模态框
	function showUpdateModal(name,id){
		/* $("#supplierName").val(supplierName);
		$("#categoryName").val(categoryName);*/
		$('#myModalLabel').html("修改属性组");
		$("#saveBtn").attr("onclick","updateAttrGroup()"); 
		$("#groupName").val(name);
		$("#groupId").val(id);
		$('#myModal').modal({keyboard: true});
	}
    //弹出添加模态框
	function showAddModal(name){
		$("#groupName").val("");
		$('#myModalLabel').html("添加属性组");
		$("#saveBtn").attr("onclick","addAttrGroup()"); 
		$("#groupName").val(name);
		$('#myModal').modal({keyboard: true});
	}
    //添加属性组
    function addAttrGroup(){
    	var params = $("#attrGroupForm").serialize();
    	params = decodeURIComponent(params,true);
    	$.ajax({
    		url:"<%=request.getContextPath()%>/productAttrGroup/ProductAttrGroup_addAttrGroup?"+params,
    		dataType:"json",
    		success:function(value){
    			alert(value.message);
    			if(value.success==true){
    				location.href='<%=request.getContextPath()%>/productAttrGroup/ProductAttrGroup_listByPage?t1.categoryId=${t1.categoryId}';
    			}
		
    		}
    	});
    }
    //修改属性组
    function updateAttrGroup(){
    	
    	var params = $("#attrGroupForm").serialize();
    	params = decodeURIComponent(params,true);
    	$.ajax({
    		url:"<%=request.getContextPath()%>/productAttrGroup/ProductAttrGroup_updateAttrGroup?"+params,
    		dataType:"json",
    		success:function(value){
    			alert(value.message);
    			if(value.success==true){
    				location.href='<%=request.getContextPath()%>/productAttrGroup/ProductAttrGroup_listByPage?t1.categoryId=${t1.categoryId}';
    			}
		
    		}
    	});
    }
    
    function showAttrMapping(id){
    	alert(id)
    }
  
    
    </script>
</head>

<body>

<div class="panel panel-primary">
  <div class="panel-heading">选择属性组 </div>
  <br>
  <c:if test="${params=='productAttrMng' }">
	  <div class="text-center">
	  	<button type="button" onclick="showAddModal()" class="btn btn-default">增加属性组</button>
  </div></c:if>
  <div class="panel-body"></div>
		
		<table class="table table-bordered table-hover">
		    <s:iterator value="#list">
			    <tr>
					 <th style="cursor:pointer">${name }</th>
				     <th>
					 	<c:if test="${params=='productAttrMng' }">
					        <a class="btn btn-primary btn-sm" onclick="showUpdateModal('${name }','${id }')" href="#" role="button" >修改</a>
				            <a class="btn btn-primary btn-sm" target="groupAttrShow" href="<%=request.getContextPath()%>/productAttr/ProductAttr_listByPage?t1.groupId=${id}&t1.category.id=${t1.categoryId}&attrGroupName=${name }&params=productAttrMng" role="button" >管理属性</a>
				      	</c:if>
				      	<c:if test="${params=='productAttrMappingMng' }">
				      		<a class="btn btn-primary btn-sm" target="groupAttrShow" href="<%=request.getContextPath()%>/productAttr/ProductAttr_listByPage?t1.groupId=${id}&t1.category.id=${t1.categoryId}&attrGroupName=${name }&params=productAttrMappingMng" role="button" >管理属性</a>
				      	</c:if>
				     </th>
			    </tr>        
		    </s:iterator>
		</table>
</div>
<section id="main-content">
    <p>
        <div class="text-center" display="inline">
            <ul id="pagination-demo" class="pagination-sm"></ul>
            <br>共${pageCount}页,共${recordsCount}条记录
        </div>
    </p>
</section>
<!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	    <div class="modal-dialog" style="width:400px">
	        <div class="modal-content text-center">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	                <h4 class="modal-title" id="myModalLabel"></h4>
	            </div>
	            <div class="modal-body" style="text-align: center">
	            	<form id="attrGroupForm">
		            		<div class="input-group text-center" style="width: 300px">
			             		<span class="input-group-addon">属性组名称</span>
		            			<input type="text"  id="groupName" name="t.name" class="form-control">
		            		</div>
				            <input type="hidden" name="t.categoryId" value="${t1.categoryId }">
		            		<input type="hidden" name="t.id" id="groupId">
		            	<br><br>
		            	<button id="saveBtn" type="button" class="btn btn-primary">保存</button>
	            	</form>
	            </div>
	        </div><!-- /.modal-content -->
	    </div><!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
</body>
</html>
